local anzhou = fk.CreateSkill {
  name = "th_anzhou",
}

anzhou:addEffect(fk.FinishRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(anzhou.name) and (target:getHandcardNum() > player:getHandcardNum() or target.hp > player.hp) and data.card and data.card.suit ~= Card.Spade
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = anzhou.name,
      prompt = "#th_anzhou-invoke:"..target.id
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local new_card = Fk:cloneCard(data.card.name, Card.Spade, data.card.number)
    new_card.skillName = anzhou.name
    new_card.id = data.card.id
    data.card = new_card
    room:sendLog{
      type = "#ChangedJudge",
      from = player.id,
      to = { data.who.id },
      arg2 = new_card:toLogString(),
      arg = anzhou.name,
    }
  end,
})
anzhou:addEffect(fk.EventPhaseProceeding, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
      return player:hasSkill(anzhou.name) and target ~= player and target.phase == Player.Start
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = anzhou.name,
      prompt = "#th_anzhou-judge:"..target.id
    })
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local judge = {
      who = target,
      reason = anzhou.name,
      pattern = ".|.|black"
    }
    room:judge(judge)
    if not target.dead and judge.card and judge.card.color == Card.Black then
      -- room:askForDiscard(player, 1, 1, true, th_anzhou.name, false)
      -- room:askForDiscard(target, 1, 1, true, th_anzhou.name, false)
      if not player:isNude() then
        room:throwCard(room:askToChooseCard(player, {target = player, flag = "he", skill_name = anzhou.name}), anzhou.name, player, player)
      end
      if not target:isNude() then
        room:throwCard(room:askToChooseCard(player, {target = target, flag = "he", skill_name = anzhou.name}), anzhou.name, target, player)
      end
    end
  end,
})

Fk:loadTranslationTable{
  ["th_anzhou"] = "暗咒",
  [":th_anzhou"] = "体力值或手牌数大于你的角色的判定结果生效前，你可以将判定结果改为♠；其他角色的准备阶段，你可以令其判定，若为黑色，你弃置你与其一张牌。",

  ["#th_anzhou-invoke"] = "暗咒：你可以将 %src 的判定结果改为♠",
  ["#th_anzhou-judge"] = "暗咒：你可以令 %src 判定，若为黑色，你与其须弃置一张牌。",
}

return anzhou